package com.taxsystem.chengwenzhi.sscx;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.main.taxsystem.R;
import com.taxsystem.huangguangxing.login.LoginActivity;
import com.taxsystem.huangguangxing.login.LoginMassege;

public class SscxActivity extends Activity {
	private static final String TAG="TaxrelatedcheckMainActivity";
	private static final int DJXXCX = 0;//登记信息查询
	private static final int SEHDCX = 1;//税额核定查询
	private static final int FPZGRD = 2;//发票资格认定
	private static final int SPBJCX =3;//审批办结查询
	private static final int SBFCX = 4;//社保费查询
	private static final int JFQKCX = 5;//缴费情况查询
	private final static String TITLES[] = { 
		"登记信息查询", 
		"纳税核定查询", 
		"发票资格认定", 
		"审批办结查询", 
		"社保缴费查询",
		"缴税情况查询 " };
	private final static int[] DRAWABLE_ID = {
		R.drawable.djxxcx,
		R.drawable.nshdcx,
		R.drawable.sbjfcx,//TODO:没有切片
		R.drawable.sbjfcx,//TODO:没有切片
		R.drawable.sbjfcx,
		R.drawable.sbjfcx//TODO:没有切片
	};
	private GridView gridView = null;
	private ArrayList<HashMap<String,Object>> list = null;
	private SimpleAdapter adapter =null;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

//		若用户未登陆，则跳转至登陆Activity
		if(!LoginMassege.isLogin()){
			Intent loginIntent = new Intent(SscxActivity.this,LoginActivity.class);
			startActivity(loginIntent);
			this.finish();
			return;
		}
		
		setContentView(R.layout.grid_view_layout_cwz);
		gridView = (GridView) findViewById(R.id.gridView);
		
		ActionBar bar = getActionBar();
        bar.setHomeButtonEnabled(true);
        bar.setIcon(R.drawable.actionbar_icon);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setBackgroundDrawable(new ColorDrawable(0xff34a4f7));

		list= new ArrayList<HashMap<String, Object>>();
		for (int i = 0; i < TITLES.length; i++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("title", TITLES[i]);// 添加标题
			map.put("icon", DRAWABLE_ID[i]);// 添加图像资源的ID
			list.add(map);
		}
		adapter = new SimpleAdapter(this, list,
				R.layout.grid_item, new String[] {
						"icon", "title" }, new int[] { R.id.image_item,
						R.id.text_item });
		gridView.setAdapter(adapter);
		gridView.setOnItemClickListener(new ItemClickListener());
	}

	class ItemClickListener implements OnItemClickListener {
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			Intent intent = null;
			switch(position){
			case DJXXCX:{
				intent = new Intent(SscxActivity.this,DjxxcxActivity.class);
				break;
			}
			case SEHDCX:{
				intent = new Intent(SscxActivity.this,SehdcxActivity.class);
				break;
			}
			case FPZGRD:{
				intent = new Intent(SscxActivity.this,FpzgrdActivity.class);
				break;
			}
			case SPBJCX:{
				intent = new Intent(SscxActivity.this,SpbjcxActivity.class);
				break;
			}
			case SBFCX:{
				intent = new Intent(SscxActivity.this,SbfcxActivity.class);
				break;
			}
			case JFQKCX:{
				intent = new Intent(SscxActivity.this,JfqkcxActivity.class);
				break;
			}
			default:
				Log.v(TAG,"error selected");
			}
			startActivity(intent);
		}
	}

}
